//
//  ShopDetailViewController.m
//  ShouYi
//
//  Created by yrapp on 16/3/10.
//  Copyright © 2016年 yurui. All rights reserved.
//

#import "ShopDetailViewController.h"
#import "ShopDetailTableViewCell.h"
#import "DCPicScrollView.h"
#import "DCWebImageManager.h"

#import "HdListModel.h"
#import "prolistModel.h"

//型号cell
#import "typeModel.h"
#import "addCartTypeTableViewCell.h"


#import "CartTableViewController.h"
//IQKeyboard 禁用
#import "IQKeyboardManager.h"

@interface ShopDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIWebViewDelegate,UIGestureRecognizerDelegate>
//more View
@property (nonatomic,strong) UIView *moreView;
//分享
@property (nonatomic,strong) UIButton *shareButton;
//回到首页
@property (nonatomic,strong) UIButton *backMainButton;

//header
@property (nonatomic,strong)UIView *headerView;
@property (nonatomic,strong)UIButton *backButton;
@property (nonatomic,strong)UIButton *gouwuButton;
@property (nonatomic,strong)UIButton *moreButton;
//foot
@property (nonatomic,strong)UIButton *buyButton;
@property (nonatomic,strong)UIButton *sellButton;
@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)UITableView *payTableView;
//轮播图
@property (nonatomic,strong)NSMutableArray *hdlistArray;
//底层半透明层
@property (nonatomic,strong)UIView *bgView;
//卖视图
@property (nonatomic,strong)sellFootView *sellView;
//买视图
@property (nonatomic,strong)addCartFootView *cartView;
//商品详情的 H5
@property (nonatomic,strong)UIWebView *shopWeb;
//记录H5界面的长度
@property (nonatomic,assign)CGFloat WebH;
@end

@implementation ShopDetailViewController
{
    
    BOOL _wasKeyboardManagerEnabled;
    
}
- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBarHidden = YES;
}


-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    _wasKeyboardManagerEnabled = [[IQKeyboardManager sharedManager] isEnabled];
    [[IQKeyboardManager sharedManager] setEnable:NO];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[IQKeyboardManager sharedManager] setEnable:_wasKeyboardManagerEnabled];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kViewBackColor;
    [self addTableView];
    [self addHeaderAndFoot];
    
    
    
    //webH置0
    self.WebH = 0;
    //解析轮播图(解析完 添加到tabView上)
    [self setUpDataForHdlist];
    
    [self addBgView];
    // Do any additional setup after loading the view.
    
    
    //通知监控键盘
    // 解决键盘遮挡问题
    //选择didShow是因为需要键盘的高度
    //选择willHide是因为视图frame重置需要优先于键盘消失，否则表现得不连贯
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasHide:)name:UIKeyboardWillHideNotification object:nil];
    
    
    
    //moreButton
    [self addMoreView];
}
#pragma mark --- 添加视图 ---
- (void)addHeaderAndFoot {
    
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 64)];
    self.headerView.backgroundColor = kBackGroundColor;
    self.headerView.alpha = 0;
    [self.view addSubview:self.headerView];
    
    self.backButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.backButton.frame = CGRectMake(20, 20, 32, 32);
    [self.backButton setBackgroundImage:[UIImage imageNamed:@"btn_xiangqing_fh"] forState:(UIControlStateNormal)];
    [self.backButton addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.backButton];
    
    //购物车按钮
    self.gouwuButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.gouwuButton.frame = CGRectMake(kWidth - 32 - 10 - 10 - 32, 20, 32, 32);
    [self.gouwuButton setBackgroundImage:[UIImage imageNamed:@"btn_xiangqing_gw"] forState:(UIControlStateNormal)];
    [self.gouwuButton addTarget:self action:@selector(toGouwu) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.gouwuButton];
    //更多
    self.moreButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.moreButton.frame = CGRectMake(kWidth - 32 - 10, 20, 32, 32);
    [self.moreButton setBackgroundImage:[UIImage imageNamed:@"btn_xiangqing_fx"] forState:(UIControlStateNormal)];
    [self.moreButton addTarget:self action:@selector(hiddenMoreView) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.moreButton];
    
    self.buyButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.buyButton.frame = CGRectMake(0, kHeight - 44, kWidth / 2, 44);
    [self.buyButton setTitle:@"买" forState:(UIControlStateNormal)];
    self.buyButton.backgroundColor = [UIColor colorWithRed:251.0/255 green:151.0/255 blue:24.0/255 alpha:1];
    [self.buyButton addTarget:self action:@selector(buyButtonClicek) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.buyButton];
    
    self.sellButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.sellButton.frame = CGRectMake(kWidth / 2, kHeight - 44, kWidth / 2, 44);
    [self.sellButton setTitle:@"卖" forState:(UIControlStateNormal)];
    self.sellButton.backgroundColor = [UIColor colorWithRed:220.0/255 green:54.0/255 blue:40.0/255 alpha:1];
    [self.sellButton addTarget:self action:@selector(sellButtonClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.sellButton];
}

//添加更多功能
- (void)addMoreView {
    
    self.moreView = [[UIView alloc] initWithFrame:CGRectMake(kWidth - 100, 74,90, 60)];
    
    self.moreView.backgroundColor = [UIColor grayColor];
    self.moreView.hidden = YES;
    [self.view addSubview:self.moreView];
    
    //背景三角号
    UIImageView *sanjiaoImage = [[UIImageView alloc] initWithFrame:CGRectMake(90 - 20, -10, 15, 10)];
    sanjiaoImage.image = [UIImage imageNamed:@"bg_fenx1"];
    [self.moreView addSubview:sanjiaoImage];
    
    //背景图片
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 60)];
    backImage.image = [UIImage imageNamed:@"bg_fenx2"];
    backImage.userInteractionEnabled = YES;
    [self.moreView addSubview:backImage];
    
    //分享按钮
    self.shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.shareButton.frame = CGRectMake(15,5, 60, 20);
    [self.shareButton setImage:[UIImage imageNamed:@"btn_fenx"] forState:(UIControlStateNormal)];
  //  [self.shareButton addTarget:self action:@selector(shareWithUM) forControlEvents:UIControlEventTouchUpInside];
    [self.moreView addSubview:self.shareButton];
    
    //回到首页按钮
    self.backMainButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.backMainButton.frame = CGRectMake(15, 30 + 5 , 60, 20);
    [self.backMainButton setImage:[UIImage imageNamed:@"btn_zhuanf"] forState:(UIControlStateNormal)];
    [self.backMainButton addTarget:self action:@selector(backMain) forControlEvents:(UIControlEventTouchUpInside)];
    [self.moreView addSubview:self.backMainButton];
}


//添加tableView
- (void)addTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,-20, kWidth, kHeight) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[ShopDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellTwo"];
    [self.tableView registerClass:[ShopDetailWebTableViewCell class] forCellReuseIdentifier:@"webCell"];
}

//添加底层图片
- (void)addBgView {
    
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    self.bgView.backgroundColor = [UIColor blackColor];
    self.bgView.alpha = 0.5;
    self.bgView.hidden = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClickBgView)];
    //设置轻拍次数
    tap.numberOfTapsRequired = 1;
    // 把轻拍手势 加到 视图上
    [self.bgView addGestureRecognizer:tap];
    [self.view addSubview:self.bgView];
    
    //添加 点卖按钮出现的 界面
    self.sellView = [[sellFootView alloc] initWithFrame:CGRectMake(0, kHeight - 88, kWidth, 88) shangjia:nil share:nil cancel:nil];
    self.sellView.hidden = YES;
        //上架按钮
    [self.sellView.shangjiaButton addTarget:self action:@selector(toShangjia:) forControlEvents:(UIControlEventTouchUpInside)];
        //取消按钮
    [self.sellView.cancelButton addTarget:self action:@selector(toCancel:) forControlEvents:(UIControlEventTouchUpInside)];
        //分享
    [self.sellView.shareButton addTarget:self action:@selector(toShare:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:self.sellView];
    
    //添加点击买按钮出现的 界面
    self.cartView = [[addCartFootView alloc] initWithFrame:CGRectMake(0, kHeight / 5 * 2, kWidth,kHeight / 5 * 3) cancel:nil addCart:nil pay:nil];
    self.cartView.backgroundColor = [UIColor whiteColor];
    self.cartView.hidden = YES;
    [self.view addSubview:self.cartView];
        //加入购物车按钮
    [self.cartView.addCartButton addTarget:self action:@selector(addGouWuClick) forControlEvents:(UIControlEventTouchUpInside)];
    
    //加入购物车界面的 tableView
    self.cartView.payTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.cartView.payTableView.delegate = self;
    self.cartView.payTableView.dataSource = self;
    [self.cartView.payTableView registerClass:[addCartTypeTableViewCell class] forCellReuseIdentifier:@"payCell"];
    [self.cartView.payTableView registerClass:[addCartNumTableViewCell class] forCellReuseIdentifier:@"numCell"];
    
}


//添加轮播图
- (void)addLunbo {
    
    NSMutableArray *UrlStringArray = [NSMutableArray array];
    
    for (int i = 0; i < self.hdlistArray.count; i++) {
        HdListModel *model = self.hdlistArray[i];
        [UrlStringArray addObject:model.picurl];
    }

    DCPicScrollView  *picView = [DCPicScrollView picScrollViewWithFrame:CGRectMake(0, 64, self.view.frame.size.width,kHeight / 4) WithImageUrls:UrlStringArray];
    //显示顺序和数组顺序一致
    // 占位图
    picView.placeImage = [UIImage imageNamed:@""];
    //图片被点击事件,当前第几张图片被点击了,和数组顺序一致
    [picView setImageViewDidTapAtIndex:^(NSInteger index) {
        
        // 点击图片  调用的方法
        _moreView.hidden = YES;
        
    }];
    //default is 2.0f,如果小于0.5不自动播放
    picView.AutoScrollDelay = 2.0f;
    //  [self.view addSubview:picView];
    self.tableView.tableHeaderView = picView;
    //下载失败重复下载次数,默认不重复,
    [[DCWebImageManager shareManager] setDownloadImageRepeatCount:1];
    //图片下载失败会调用该block(如果设置了重复下载次数,则会在重复下载完后,假如还没下载成功,就会调用该block)
    //error错误信息
    //url下载失败的imageurl
    [[DCWebImageManager shareManager] setDownLoadImageError:^(NSError *error, NSString *url) {
        NSLog(@"%@",error);
    }];
    
}


- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark --- 数据处理 ---
- (void)setUpDataForHdlist {
    
    [LORequestManger GET:KHdlist success:^(id response) {
        
        NSArray *array = (NSArray *)response;
        
        for (NSDictionary *dic in array) {
            
            HdListModel *model = [HdListModel setUpdateDic:dic];
            
            [self.hdlistArray addObject:model];
        }
        [self addLunbo];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

//懒加载
- (NSMutableArray *)hdlistArray {
    if (!_hdlistArray) {
        _hdlistArray = [NSMutableArray array];
    }
    return _hdlistArray;
}
#pragma mark --- 手势 && 按钮响应事件----

//返回首页
- (void)backMain {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
    
}

//购物车按钮响应事件
- (void)toGouwu {
    self.hidesBottomBarWhenPushed = YES;
    CartTableViewController *cartVC = [[CartTableViewController alloc] init];
    [self.navigationController pushViewController:cartVC animated:YES];
    
}


//半透明底色点击 隐藏
- (void)tapClickBgView {
    self.bgView.hidden = YES;
    self.sellView.hidden = YES;
    self.cartView.hidden = YES;
    self.moreView.hidden = YES;
    //回收键盘
    UITextField *field = (UITextField *)[self.view viewWithTag:3000];
    [field endEditing:YES];
    
}
//点击买按钮
- (void)buyButtonClicek {
    self.bgView.hidden = NO;
    self.cartView.hidden = NO;
    self.moreView.hidden = YES;

}
// 买 >> 加入购物车
- (void)addGouWuClick {
    
    [self showAlertMessage:@"成功加入购物车"];
    
}

//点击卖按钮
- (void)sellButtonClick {
     self.bgView.hidden = NO;
    self.sellView.hidden = NO;
    self.moreView.hidden = YES;

}
// 卖 >> 直接上架
- (void)toShangjia:(UIButton *)button {
    
    [self showAlertMessage:@"添加成功"];
}
// 卖 >> 分享
- (void)toShare:(UIButton *)button {
    NSLog(@"卖 分享");
}
// 卖 >> 取消
- (void)toCancel:(UIButton *)button {
    [self tapClickBgView];
}

//商品详情webVeiw
- (void)tapClick:(UIGestureRecognizer *)tap {
    
    self.moreView.hidden = YES;
}

//隐藏显示  moreView
- (void)hiddenMoreView {
    
    self.moreView.hidden = !self.moreView.hidden;
    
}

//选择型号尺码的按钮
- (void)stypeButtonClick:(UIButton *)button {
    
    NSLog(@"%@",button.titleLabel.text);
    
    
    if (button.tag < 200) {
        // 操作尺码按钮
        NSArray *array = @[@"S",@"M",@"L",@"XL",@"高端大气上档次",@"低调奢华有内涵",@"买一送一九块九包邮"];
        
        for (int i = 0; i < array.count; i++) {
            
            UIButton *btn = (UIButton *)[self.view viewWithTag:100 + i];
            btn.backgroundColor = [UIColor whiteColor];
        }
    }else {
        //操作颜色按钮
        NSArray *array = @[@"白色",@"黑色",@"藏青黑色"];
        for (int i = 0; i < array.count; i++) {
            UIButton *btn = (UIButton *)[self.view viewWithTag:200 + i];
            btn.backgroundColor = [UIColor whiteColor];
        }
        
    }
    
    button.backgroundColor = [UIColor redColor];
    
}

//添加||减少商品数量
- (void)plusButtonClick {
    
    UITextField *field = (UITextField *)[self.view viewWithTag:3000];
    int value = [field.text intValue];
    value ++;
    field.text = [NSString stringWithFormat:@"%d",value];
    
}

- (void)deleteButtonClick {
    
    UITextField *field = (UITextField *)[self.view viewWithTag:3000];
    int value = [field.text intValue];
    value --;
    field.text = [NSString stringWithFormat:@"%d",value];
}


#pragma mark --- tableView ---

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.tableView) {
        return 3;
    }else {
        return 3;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
#pragma mark --- 商品详情cell ---
    if (self.tableView == tableView) {
        
        if (indexPath.row == 0) {
            ShopDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
            cell.tag = 1000;
            [cell setModel:self.proModel];
            NSLog(@"cell");
            return cell;
        }
        
        if (indexPath.row == 1) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellTwo" forIndexPath:indexPath];
            cell.textLabel.text = @"商品详情";
            cell.textLabel.textAlignment = NSTextAlignmentCenter;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        
        if (indexPath.row == 2) {
            ShopDetailWebTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"webCell" forIndexPath:indexPath];
            
            NSArray *webArray = cell.contentView.subviews;
            if (webArray.count == 0) {
                self.shopWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 10)];
                
                
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
                //设置轻拍次数
                tap.numberOfTapsRequired = 1;
                [self.shopWeb addGestureRecognizer:tap];
                tap.delegate = self;
                tap.cancelsTouchesInView = NO;
                
                
                [cell.contentView addSubview:self.shopWeb];
                NSURL *tempUrl = [NSURL URLWithString:@"http://war.firefox.163.com/16/0413/07/C2HLZE7TQA48OMB0.html"];
                NSURLRequest *request = [NSURLRequest requestWithURL:tempUrl];
                self.shopWeb.delegate = self;
                self.shopWeb.scrollView.bounces = NO;
                [self.shopWeb loadRequest:request];
                
                
            }
            self.shopWeb.frame = CGRectMake(0, 0, kWidth, self.WebH);
            return cell;
        }
        
    }else {
#pragma mark --- 颜色尺码cell ---
        
        if (indexPath.row == 0 || indexPath.row == 1) {
            addCartTypeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"payCell" forIndexPath:indexPath];
            NSArray *numViewArray = cell.contentView.subviews;
            if (numViewArray.count == 0) {
                
                NSArray *array;
                UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 50, 20)];
    
                if (indexPath.row == 0) {
                    array = @[@"S",@"M",@"L",@"XL",@"高端大气上档次",@"低调奢华有内涵",@"买一送一九块九包邮"];
                    typeLabel.text = @"尺码";
                }else {
                    array = @[@"白色",@"黑色",@"藏青黑色"];
                    typeLabel.text = @"颜色";
                }
                
                [typeLabel sizeToFit];
                [cell.contentView addSubview:typeLabel];
                StyleView *typeView = [StyleView styleViewWith:array row:1 + indexPath.row];
                for (int i = 0; i < array.count; i++) {
                    UIButton *btn = [typeView viewWithTag:100 * (indexPath.row + 1) + i];
                    [btn addTarget:self action:@selector(stypeButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
                }
                
                cell.tag = 2000 + indexPath.row;
                [cell.contentView addSubview:typeView];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else {
            
            addCartNumTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"numCell" forIndexPath:indexPath];
            [cell.plusButton addTarget:self action:@selector(plusButtonClick) forControlEvents:(UIControlEventTouchUpInside)];
            [cell.deleButton addTarget:self action:@selector(deleteButtonClick) forControlEvents:(UIControlEventTouchUpInside)];
            cell.numField.delegate = self;
            return cell;
            
            
            
        }
        
        
    }
    
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (tableView == self.tableView) {
        
        if (indexPath.row == 0) {
            
            ShopDetailTableViewCell *cell = [[ShopDetailTableViewCell alloc] init];
            NSLog(@"height  tableView");
            return [cell setModelForHeight:self.proModel];
        }
        if (indexPath.row == 2) {
            
            return self.WebH;
            
        }
    }else {
#pragma mark --- 动态颜色型号高度 ---
        if (indexPath.row == 1 || indexPath.row == 0) {

            NSArray *array;
            if (indexPath.row == 0) {
                array = @[@"S",@"M",@"L",@"XL",@"高端大气上档次",@"低调奢华有内涵",@"买一送一九块九包邮"];
            }else {
                array = @[@"白色",@"黑色",@"藏青黑色"];
            }

            
            StyleView *view = [StyleView styleViewWith:array row:indexPath.row];
            
            NSLog(@"row = %ld  %f",(long)indexPath.row,view.frame.size.height);
            
            return view.frame.size.height;
            
        }
        
        return 71.5;
        
        
    }
    return 30;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITextField *field = (UITextField *)[self.view viewWithTag:3000];
    [field endEditing:YES];
    
    self.moreView.hidden = YES;
}


//webView解析完成
- (void)webViewDidFinishLoad:(UIWebView *)webView {
//    [webView sizeToFit];
//
//    NSLog(@"web H:%f  web W:%f",webView.frame.size.height,webView.frame.size.width);
//    self.WebH = webView.frame.size.height;
    
    CGRect frame = webView.frame;
    frame.size.width = kWidth;
    frame.size.height = 1;
    
    webView.scrollView.scrollEnabled = NO;
    webView.frame = frame;
    
    frame.size.height = webView.scrollView.contentSize.height;
    
    NSLog(@"frame = %@", [NSValue valueWithCGRect:frame]);
    self.WebH = frame.size.height;
    
    
     NSLog(@"web H:%f  web W:%f",webView.frame.size.height,webView.frame.size.width);
    [self.tableView reloadData];
    
}

//计算字符串长度
- (CGRect)NSStringLong:(NSString *)str {
    
    CGRect frame = [str boundingRectWithSize:CGSizeMake(1000, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName] context:nil];
    return frame;
    
}

#pragma mark --- 操作键盘 ---
//显示键盘
-(void)keyboardWasShown:(NSNotification*)notification
{
    //获取键盘高度
    NSValue* value=notification.userInfo[UIKeyboardFrameBeginUserInfoKey];
    CGFloat keyBoradHeight=[value CGRectValue].size.height;
    //    NSNumber* animationTime=notification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
    //    double time=[animationTime doubleValue];
    //获取被遮挡控件距离controller底部的距离
    
    NSLog(@" 键盘的    %f",self.view.frame.origin.y);
    
    float a=self.view.frame.origin.y+self.view.frame.size.height;
    float b = self.view.frame.size.height-a;
    if (b<keyBoradHeight)
    {
        //动画效果
        [UIView animateWithDuration:0.5
                         animations:^
         {
             //键盘被挡住了
             CGRect viewCGrect=self.view.frame;
             //视图应该上移所以是－
             viewCGrect.origin.y=viewCGrect.origin.y-(keyBoradHeight-b) + 50;
             [self.view setFrame:viewCGrect];
             
         } completion:nil];
        
    }
    
}
//隐藏键盘
-(void)keyboardWasHide:(NSNotification*)notification
{
    CGRect viewCGrect=self.view.frame;
    viewCGrect.origin.y = 0;
    [self.view setFrame:viewCGrect];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//滑动隐藏键盘
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == self.cartView.payTableView) {
        
        UITextField *field = (UITextField *)[self.view viewWithTag:3000];
        [field endEditing:YES];
        
    }
}



#pragma mark --- 提醒视图 ---
//添加 收藏提醒框图
- (void)showAlertMessage:(NSString *)message {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alert show];
    [self performSelector:@selector(dimissAlert:) withObject:alert afterDelay:1];
    
}

// 提醒视图消失
- (void)dimissAlert:(UIAlertView *)alert {
    
    if (alert) {
        [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
    }
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    
    return YES;
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
